package util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

//import javax.swing.JOptionPane;

public class MoneyUtil {
	public Moneyset getvips(){
		ArrayList<Integer> a = getVip();
		Moneyset vip = new Moneyset(
				a.get(0),
				a.get(1),
				a.get(2),
				a.get(3),
				a.get(4),
				a.get(5)
				);
		return vip;
	}
	public ArrayList<Integer> getVip(){
		ArrayList<Integer> a = new ArrayList<Integer>();
		try{
			Connection conn = DBUtil.getConnection();
			Statement sta = conn.createStatement();
			String sql = "select * from money";
			ResultSet set = sta.executeQuery(sql);
			while(set.next()){
				a.add(Integer.parseInt(set.getString(1)));
				a.add(Integer.parseInt(set.getString(2)));
				a.add(Integer.parseInt(set.getString(3)));
				a.add(Integer.parseInt(set.getString(4)));
				a.add(Integer.parseInt(set.getString(5)));
				a.add(Integer.parseInt(set.getString(6)));
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return a;
	}
	public void updatevip(Moneyset vip){
		try{
			Connection conn = DBUtil.getConnection();
			Statement sta = conn.createStatement();
			String sql = "update money set mlifa = "+vip.getMlifa() + ", mranfa = " + vip.getMranfa()+",mtanfa = "+vip.getMtanfa()+",mtanran = "+vip.getMtanran()+",mhuli = " + vip.getMhuli() + ", mxifa = "+ vip.getMxifa();
			sta.execute(sql);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
